<template>
  <header>
    <div>
      <span>TODOLIST</span>
      <input
        type="text"
        placeholder="添加toDo"
        v-model="inputval"
        @keydown.enter="add"
      />
    </div>
  </header>
</template>
<script>
import { mapMutations } from 'vuex'
export default {
  data() {
    return {
      inputval: "",
    };
  },
  methods: {
    ...mapMutations(['addList']),
    add() {
      if (this.inputval) {
        let obj = {
          msg: this.inputval,
          flag: false, // false 正在进行 true 已完成
          showSpan: true, // 是否显示 span标签
        };
        // this.$store.commit("addList",obj);
        this.addList(obj);
        this.inputval = "";
        this.$router.push('/about');
      }
    },
  },
};
</script>
<style lang="scss">
header {
  width: 100%;
  height: 50px;
  background-color: #444;
}

header div {
  width: 600px;
  margin: 0 auto;
  height: 100%;
  /* 将元素盒转化为弹性盒子 */
  display: flex;
  /* 
            justify-content 主轴方向上的对齐方式
            space-between 两边对齐 中间留白
             */
  justify-content: space-between;
  /* 侧轴的对齐方式 */
  align-items: center;
  color: #fff;
}

header div span {
  font-size: 30px;
  font-weight: bold;
}

header div input {
  outline: none;
  border: none;
  width: 300px;
  height: 30px;
  padding-left: 15px;
  border-radius: 6px;
}
</style>